// pages/webView/webview.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    src:""
  },
  onLoad: function (options) {
    let jwt = wx.getStorageSync('jwt')
    let split = options.url.split('#')
    let params = ''
    for(var i in options){
      if(i!='url'){
        params+= '&'+i+'='+options[i]
      }
    }
    let user = wx.getStorageSync('userInfo')
    console.log(options.url + '?jwt=' + jwt + '&id=' + (user ? user.id : "") + params)
    this.setData({
      src: options.url + '?jwt=' + jwt + '&id=' + (user?user.id:null)+ params 
    })
  },
  message(e){
    console.log(e)
    switch (e.detail.data[0].form){
      case 1:
        this.selectCity(e.detail.data)
      break;
      case 2:
        this.selectStore(e.detail.data)
    }
  },
  // 选择城市
  selectCity(e){
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    console.log(prevPage.data)
    prevPage.data.distanceInfo.lat = Number(e[0].lat)
    prevPage.data.distanceInfo.lot = Number(e[0].lot)
    prevPage.setData({
      prevPage: prevPage.data.distanceInfo,
      cityId: e[0].cityId,
      formType: 1
    })
  },
  // 充值选择加油站
  selectStore(e){
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      stationId:e[0].storeId
    })
  }, 

  onShareAppMessage: function () {

  }
})